home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 175 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Exceptions vs. assertions
  5. Date: 2 Jan 1996 14:26:20 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4cbfac$kst@dawn.mmm.com>
  8. References: <4al1hn$73e@news.nstn.ca> <4bpt9b$cb5@news2.ios.com> <4bqb7t$bca@sundog.tiac.net>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Chris Page (page@tiac.net) wrote:
  13. > lalit@gramercy.ios.com (lalit gidwani) wrote:
  14.  
  15. > :Someone needs to point me to a proper architecture for using Exceptions.
  16. > :Several times I have come across articles that seem to apply that
  17. > :any time there is an error condition, an exception should be used.
  18. > :One of their arguments for doing this is that the program does
  19. > :not have to check for the return value of functions. The exception
  20. > :handling mechanism can be used instead. Since I have run into
  21. > :a lot of code where a lot of erro-checking has to be done I thought
  22. > :that exceptions would be helpful. However, the the note that appears
  23. > :above implies that C++ exception-handling should be used only
  24. > :for catastrophic errors.
  25.  
  26. > :LG
  27.  
  28. > Exceptions do not cost anything until you use them.  My rule of thumb
  29.  
  30. The truth of this statement is very dependent upon the implementation
  31. of exceptions in your system.  But I have found that most implementations
  32. seem to strive toward this goal -- that performance of exception code
  33. compared with equivalent return-value code only suffers when exceptions
  34. are actually thrown.
  35.  
  36. > is this: If I expect a condition to occur during normal operation of
  37. > my program, then I do not use exceptions for it.  I use exceptions,
  38. > only for exceptionally conditions, which I do not expect to occur, but
  39. > I have to anticipate.
  40.  
  41. This is a good approach.  The issue of whether to throw exceptions or
  42. return status values is best decided by how likely the failure is than
  43. by how catastrophic it is.  (Besides, the caller of a function knows
  44. better than the function itself how costly the failure is.)
  45. --
  46. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  47. 3M Company                      phone:  (612) 737-4643
  48. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  49. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  50.     But 3M speaks for me -- I did not write the following line:
  51.  
  52. Opinions expressed herein are my own and may not represent those of 3M.
  53.